var income = {
    showConfirmMsg: function()
    {
        if (confirm('Are you sure you want to delete this income?') == false) {
            return false;
        }
    },
    selectMonth: function(url_data, chart) 
    {
        var today = moment().format('MM.YYYY');
        $('#select-month-to').val(today); 
        $('#select-month-from').val(today); 
        
        $('.select-month-left').click(function() {
            var id = $(this).parent('.box-date').find('input').attr('id');
            changeMonth('left', id);
        });
        
        $('.select-month-right').click(function() {
            var id = $(this).parent('.box-date').find('input').attr('id');
            changeMonth('right', id);
        });
        
        function changeMonth(where, id) {
            var data  = $('#' + id).val();
            var myarr = data.split(".");
            var month = parseInt(myarr[0], 10);
            var year  = parseInt(myarr[1], 10);
            if(where === 'left') {
                if (month == 1) {
                   month = 12;
                   year -= 1;
                } else {
                    month -= 1;
                }
            } else if(where === 'right') {
                 if (month == 12) {
                    month = 1;
                    year += 1;
                 } else {
                     month += 1;
                 }   
            }
            if (month < 10) {
                month = '0' + month;
            }
                         
            $('#' + id).val(month + "." + year); 
            
            var dateTo   = $('#select-month-to').val(); 
            var dateFrom = $('#select-month-from').val(); 
            // update grid
            $('#list').jqGrid('setGridParam',{ postData:{ 'date_to': dateTo, 'date_from': dateFrom }, search:true });
            $('#list').trigger("reloadGrid");
            // update chart
            chart.refresh('chart1', url_data);
   
            
        }
        
        $('body').on('focus', '#select-month-to', function() {
            datePickerFnk(this);
        }); 
        
        $('body').on('focus', '#select-month-from', function() {
            datePickerFnk(this);
        });
        
        function datePickerFnk(d) {
            $(d).datetimepicker({
                "format": "mm.yyyy", 
                "pickerPosition": "bottom-left", 
                "minView": "year", 
                "startView": "year",
                "autoclose": true
                }).on('changeMonth', function(ev){
                   var month = ev.date.getMonth() + 1; 
                   var year  = ev.date.getFullYear(); 
                   if (month < 10) {
                       month = '0' + month;
                   }
                   $(this).val(month + '.' + year); 
                   var dateTo   = $('#select-month-to').val(); 
                   var dateFrom = $('#select-month-from').val();  
                   // update grid
                   $('#list').jqGrid('setGridParam',{ postData:{ 'date_to': dateTo, 'date_from': dateFrom }, search:true });
                   $('#list').trigger("reloadGrid");
                   // update chart
                   chart.refresh('chart1', url_data);
                   
               });
        }
    }
}
